/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import java.sql.Connection;
import java.sql.DriverManager;
import javax.ejb.Stateless;

/**
 *
 * @author owtee
 */
@Stateless
public class Database {

    private String url = "jdbc:mysql://localhost/msg";
    private String username = "root";
    private String password = "admin";
    private Connection connection = null;

    public Connection connect() {

        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(url, username, password);

        } catch (Exception ex) {
            return null;
        }

        return connection;
    }
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    public void close() {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ex) {
        }
    }
}
